package com.start.boot.support.utils;

import java.util.List;
import java.util.Map;

/**
 * EasyUI封装
 * Created by lenovo on 2017/10/25.
 */
public class EasyUIUtils {
    private final String JSON_NULL = "[]";

    private EasyUIUtils() { }

    /**
     * 转换List<Map>中数据为EasyUI下拉框控件数据源JSON
     *
     * @param list
     *            数据源
     * @param colID
     *            ID列
     * @param colName
     *            显示列
     * @return JSON字符串
     */
    @SuppressWarnings("rawtypes")
    public static String buildComboBoxDataSource(List<Map> list, String colID, String colName) {
        StringBuilder sBuilder = new StringBuilder();

        sBuilder.append("[");
        for (Map map : list) {
            sBuilder.append("{\"id\":\"").append(map.get(colID).toString()).append("\", \"text\":\"")
                    .append(map.get(colName).toString()).append("\"},");
        }
        sBuilder.deleteCharAt(sBuilder.length() - 1).append("]");

        return sBuilder.toString();
    }



}
